home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / BordersRepeats.pprx < prev    next >
Text File  |  1993-08-06  |  10KB  |  304 lines

  1. /* This Genie puts a decorative border around a box. You will need a box containing a clip or bitmap for the corners, and one or more similar boxes for the sides. The resulting border consists of a group of individual boxes, which can be moved together if you hold down the shift key.
  2. Written by Don Cox  July '92  mods Aug 93 */
  3.  
  4. trace n
  5.  
  6. address command
  7. signal on error
  8. signal on syntax
  9. signal on halt
  10. signal on break_c
  11. signal on break_d
  12. signal on break_e
  13.  
  14. rad = 3.1415926 / 180
  15. call ppm_AutoUpdate(0)
  16. call SafeEndEdit.rexx()
  17. cr="0a"x
  18.  
  19. if ~show('l', "gdarexxsupport.library") then
  20.     if ~addlib("gdarexxsupport.library",0,-30) then
  21.             call exit_msg("Please install the gdarexxsupport.library in your libs: directory before running this Genie")
  22.  
  23. CurrentUnits = ppm_GetUnits()
  24.  
  25. select
  26.     when CurrentUnits = 1 then units="inches"
  27.     when CurrentUnits = 2 then units="millimetres"
  28.     otherwise units ="points"
  29.     end
  30.  
  31. mainbox = ppm_ClickOnBox("Click on box to be given a border")
  32. if mainbox=0 then exit_msg("No box selected")
  33. mainpos = ppm_GetBoxPosition(mainbox)
  34. mainXpos = word(mainpos, 1)
  35. mainYpos = word(mainpos, 2)
  36. mainsize = ppm_GetBoxSize(mainbox)
  37. mainangle = ppm_GetBoxAngle(mainbox)
  38.  
  39. breadthRaw =  ppm_GetUserText(6, "Width of border in "units)
  40. if breadthRaw="" then exit_msg("Aborted by User")
  41.  
  42. if CurrentUnits = 2 then breadth = breadthRaw/10   /* mm to cm */
  43. if CurrentUnits = 3 then breadth = breadthRaw/12   /* points to picas */
  44. mainheight = (word(mainsize, 2))-(breadth*2)
  45. mainwidth = (word(mainsize, 1))-(breadth*2)
  46. if mainheight<0 | mainwidth<0 then exit_msg("Impossible width: "breadthRaw)
  47.  
  48. cornerbox = ppm_ClickOnBox("Click on Box for Corner Units")
  49. if cornerbox ~=0 then do
  50.     csize = ppm_GetBoxSize(cornerbox)
  51.     cXsize = word(csize, 1)
  52.     cYsize = word(csize, 2)
  53.     cscale = ppm_GetBoxScale(cornerbox)
  54.     cscaleX = word(cscale, 1)
  55.     cscaleY = word(cscale, 2)
  56.     cangle = ppm_GetBoxAngle(cornerbox)
  57.     end
  58.  
  59. counter=0
  60.  
  61. do forever
  62.     box=ppm_ClickOnBox("Click on boxes for side units")
  63.     if box=0 then break
  64.     counter=counter+1
  65.     boxes.counter=box
  66.     call ppm_SetBoxAngle(box,0)
  67.     if counter = 5 then break
  68. end
  69.  
  70. if counter = 0 & cornerbox = 0 then exit_msg("No boxes selected for units")
  71.  
  72. sideboxes = counter /* This is the number of different units in the design */
  73.  
  74. do while counter<6
  75.     counter = counter+1
  76.     boxes.counter = boxes.1    /* pad up to 5 */
  77.     end
  78.  
  79.  
  80.  
  81. if Sideboxes>1 then do
  82.     pattern = ppm_GetUserText(Sideboxes*3, Sideboxes" boxes selected. Type in repeat pattern using abBAc etc.")
  83.     if pattern = "" then pattern = "a"
  84.     end
  85. else if Sideboxes = 1 then pattern = "a"
  86.  
  87. /* Place Corner Units */
  88. call ppm_NewGroup()
  89. call ppm_ShowStatus("Placing Corner Units")
  90. if cornerbox ~=0 then do
  91.     cbox = ppm_CloneBox(cornerbox, 0, 0)
  92.     call ppm_AddToGroup(cbox)
  93.     call ppm_SetBoxAngle(cbox,0)
  94.     call ppm_SetBoxSize(cbox, breadth, breadth)
  95.     call ppm_SetBoxScale(cbox, cscaleX*breadth/cXsize, cscaleY*breadth/cYsize)
  96.     call ppm_SetBoxPosition(cbox, mainXpos, mainYpos)
  97.     cbox2 = ppm_CloneBox(cbox, 0, 0)
  98.     call ppm_AddToGroup(cbox2)
  99.     call ppm_SetBoxPosition(cbox2, mainXpos, mainYpos+mainheight+breadth)
  100.     call ppm_SetBoxAngle(cbox2, (cangle+90)//360)
  101.     cbox3 = ppm_CloneBox(cbox, 0, 0)
  102.     call ppm_AddToGroup(cbox3)
  103.     call ppm_SetBoxPosition(cbox3, mainXpos+mainwidth+breadth, mainYpos+mainheight+breadth)
  104.     call ppm_SetBoxAngle(cbox3, (cangle+180)//360)
  105.     cbox4 = ppm_CloneBox(cbox, 0, 0)
  106.     call ppm_AddToGroup(cbox4)
  107.     call ppm_SetBoxPosition(cbox4, mainXpos+mainwidth+breadth, mainYpos)
  108.     call ppm_SetBoxAngle(cbox4, (cangle+270)//360)
  109.     call ppm_SetBoxAngle(cbox, cangle//360)
  110.     end
  111.  
  112.  
  113. if Sideboxes = 0 then exit_msg("Done")
  114.  
  115.     patternlength = length(pattern)
  116.     totalwidth = 0
  117.  
  118.  
  119.     do i=1 to patternlength
  120.         letter = substr(pattern, i, 1)
  121.         select
  122.             when letter = "a" | letter = "A" then repeats.i = ppm_CloneBox(boxes.1, 0, 0)
  123.             when letter = "b" | letter = "B" then repeats.i = ppm_CloneBox(boxes.2, 0, 0)
  124.             when letter = "c" | letter = "C" then repeats.i = ppm_CloneBox(boxes.3, 0, 0)
  125.             when letter = "d" | letter = "D" then repeats.i = ppm_CloneBox(boxes.4, 0, 0)
  126.             when letter = "e" | letter = "E" then repeats.i = ppm_CloneBox(boxes.5, 0, 0)
  127.             otherwise repeats.i = ppm_CloneBox(boxes.1, 0, 0)
  128.             end
  129.  
  130.             if datatype(letter, "upper") then repeats.i.flip = 1
  131.             else repeats.i.flip = 0
  132.  
  133.  
  134. /* Collect original size and graphic scale of each box */
  135.     repeats.i.scaleX = word(ppm_GetBoxScale(repeats.i), 1)
  136.     repeats.i.scaleY = word(ppm_GetBoxScale(repeats.i), 2)
  137.     repeats.i.width = word(ppm_GetBoxSize(repeats.i), 1)
  138.     repeats.i.height = word(ppm_GetBoxSize(repeats.i), 2)
  139.     repeats.i.scale1 = breadth/repeats.i.height
  140.     repeats.i.width2 = repeats.i.width*repeats.i.scale1
  141.     if repeats.i.flip = 1 then repeats.i.scale1 = -repeats.i.scale1
  142.  
  143.     totalwidth = totalwidth+repeats.i.width2   /* width of the whole pattern */
  144. end
  145.  
  146.  
  147. heightcount = mainheight%totalwidth /* Use integer division to get number of repeats */
  148. widthcount = mainwidth%totalwidth
  149. if widthcount = 0 | heightcount = 0 then exit_msg("Pattern too big")
  150.  
  151. Xtotalwidth = mainwidth/widthcount  /* Exact width of whole pattern */
  152. Ytotalwidth = mainheight/heightcount
  153. Xscale = Xtotalwidth/totalwidth
  154. Yscale = Ytotalwidth/totalwidth
  155.  
  156. do i = 1 to patternlength
  157.     repeats.i.widthX = repeats.i.width2*Xscale
  158.     repeats.i.widthY = repeats.i.width2*Yscale 
  159.     end
  160.  
  161.  
  162. /* Place top units  */
  163.  
  164. call ppm_ShowStatus("Placing Top Units")
  165. leftpos = mainXpos+breadth
  166. do j=1 to widthcount
  167. do i=1 to patternlength
  168.     newboxes.i = ppm_CloneBox(repeats.i, 0, 0)
  169.     call ppm_AddToGroup(newboxes.i)
  170.     call ppm_SetBoxSize(newboxes.i, repeats.i.widthX, breadth)
  171.     call ppm_SetBoxPosition(newboxes.i, leftpos, mainYpos)
  172.     call ppm_SetBoxScale(newboxes.i, (repeats.i.scaleX *repeats.i.scale1* Xscale), (repeats.i.scaleY * abs(repeats.i.scale1)) )
  173.     call ppm_SetBoxAngle(newboxes.i, 0)
  174.     leftpos = leftpos+repeats.i.widthX
  175.     end
  176. end
  177.  
  178. /* Place right side units */
  179. call ppm_ShowStatus("Placing Right Side Units")
  180. toppos = mainYpos+breadth
  181. leftpos = mainXpos+word(mainsize, 1)
  182.  
  183. do j=1 to heightcount
  184.     do i=1 to patternlength
  185.         newboxes.i = ppm_CloneBox(repeats.i, 0, 0)
  186.         call ppm_AddToGroup(newboxes.i)
  187.         call ppm_SetBoxAngle(newboxes.i, 270)
  188.         call ppm_SetBoxSize(newboxes.i, repeats.i.widthY, breadth)
  189.         call ppm_SetBoxPosition(newboxes.i, leftpos, toppos)
  190.         call ppm_SetBoxScale(newboxes.i, (repeats.i.scaleX *repeats.i.scale1* Yscale), (repeats.i.scaleY * abs(repeats.i.scale1)) )
  191.         toppos = toppos+repeats.i.widthY
  192.         end 
  193.     end
  194.  
  195.  
  196. /* Place bottom units  */
  197.  
  198. call ppm_ShowStatus("Placing Bottom Units")
  199. leftpos = mainXpos+breadth+mainwidth
  200. toppos = mainYpos+word(mainsize, 2)
  201.  
  202. do j=1 to widthcount
  203. do i=1 to patternlength
  204.     newboxes.i = ppm_CloneBox(repeats.i, 0, 0)
  205.     call ppm_AddToGroup(newboxes.i)
  206.     call ppm_SetBoxAngle(newboxes.i, 180)
  207.     call ppm_SetBoxSize(newboxes.i, repeats.i.widthX, breadth)
  208.     call ppm_SetBoxPosition(newboxes.i, leftpos, toppos)
  209.     call ppm_SetBoxScale(newboxes.i, (repeats.i.scaleX *repeats.i.scale1* Xscale), (repeats.i.scaleY * abs(repeats.i.scale1)) )
  210.     leftpos = leftpos-repeats.i.widthX
  211.     end
  212. end
  213.  
  214. /* Place left side units */
  215. call ppm_ShowStatus("Placing Left Side Units")
  216. toppos = mainYpos+breadth+mainheight
  217. leftpos = mainXpos
  218.  
  219. do j=1 to heightcount
  220.     do i=1 to patternlength
  221.         newboxes.i = ppm_CloneBox(repeats.i, 0, 0)
  222.         call ppm_AddToGroup(newboxes.i)
  223.         call ppm_SetBoxAngle(newboxes.i, 90)
  224.         call ppm_SetBoxSize(newboxes.i, repeats.i.widthY, breadth)
  225.         call ppm_SetBoxPosition(newboxes.i, leftpos, toppos)
  226.         call ppm_SetBoxScale(newboxes.i, (repeats.i.scaleX *repeats.i.scale1* Yscale), (repeats.i.scaleY * abs(repeats.i.scale1)) )
  227.         toppos = toppos-repeats.i.widthY
  228.         end 
  229.     end
  230.  
  231. /* Delete the "repeats" set of boxes  */
  232. do i = 1 to patternlength
  233.     gone = ppm_DeleteBox(repeats.i)
  234.     end
  235.  
  236. /* Set an arbitrary margin in main box  */
  237. margin = breadt